package main

import (
	"babydoge/config"
	db2 "babydoge/config/db"
	"babydoge/models"
	"flag"
	"fmt"
	"os"
)

var (
	confFile string
)

func initArgs() {
	var (
		currentDir string
		path       string
	)
	currentDir, _ = os.Getwd()
	path = currentDir + "/config/config.json"
	flag.StringVar(&confFile, "config", path, "指定config.json文件")
	flag.Parse()
}

func main() {
	var (
		db  *db2.DB
		err error
	)

	initArgs()

	if err = config.InitConfig(confFile); err != nil {
		fmt.Println("加载配置文件错误", err)
		panic(err)
	}

	if db, err = db2.NewDB(); err != nil {
		fmt.Println("连接数据库报错:", err)
		panic(err)
	}

	if config.G_config.DbDriver == "mysql" {
		if err = db.Db.Set("gorm:table_options", "ENGINE=InnoDB").AutoMigrate(&models.Queue{}); err != nil {
			fmt.Println("migrate错误:", err)
			panic(err)
		}

	} else if config.G_config.DbDriver == "sqlserver" {
		if err = db.Db.AutoMigrate(&models.Queue{}); err != nil {
			fmt.Println("migrate错误:", err)
			panic(err)
		}
	} else {
		panic("未配置数据库")
	}

	fmt.Println("migrate完成")

}
